<template>
  <basic-container>
    <div slot="header" class="detail-header">
      <div class="detail-header-left">
        <cs-card-title>{{ title }}</cs-card-title>
      </div>
      <div class="detail-header-right">
        <i class="el-icon-arrow-left" :class="current === 1 || total === 0?'disabled':''" style="cursor: pointer"
           @click="$emit('change-page','back')"></i>
        <i class="el-icon-arrow-right" :class="current *10 >= total?'disabled':''" style="cursor: pointer"
           @click="$emit('change-page','forward')"></i>
      </div>
    </div>
    <div>
      <div v-if="creativeList.length > 0" class="creative-list">
        <div class="creative-item" v-for="item in creativeList" :key="item.id" @click="$emit('click-creative', item)">
          <div class="creative-item-pic">
            <video
              v-if="item.type === 1"
              style="width: 7vw; height: 7vw"
              :src="item.creativeUrl"
            >
            </video>
            <el-image
              v-else
              style="width: 7vw; height: 7vw"
              :src="item.creativeUrl"
              :fit="'cover'">
            </el-image>
          </div>
          <div class="creative-item-content">
            <div>花费：{{ item.allExpend }}</div>
            <div>安装成本：{{ item.installCost }}</div>
          </div>
        </div>
      </div>
      <div v-else style="display: flex;justify-content: center;align-items: center">
        <el-empty description="暂无数据"></el-empty>
      </div>
    </div>
  </basic-container>
</template>

<script>
import CsCardTitle from "@/components/CsCardTitle/CsCardTitle";

export default {
  name: "TopCreative",
  components: {
    CsCardTitle
  },
  props: {
    creativeList: {
      type: Array,
      default: () => []
    },
    title: {
      type: String
    },
    current: {
      type: Number
    },
    total: {
      type: Number
    }
  },
  methods: {
    dialogType(val) {
      let type;
      let urlTail = val.split(".")[val.split(".").length - 1];
      let imgList = ["jpg", "jpeg", "png", "gif", "bmp"];
      let videoList = ["mp4", "mov", "avi", "mp3", "ogg", "rmvb", "mkv"];
      if (imgList.includes(urlTail)) {
        type = "image";
      } else if (videoList.includes(urlTail)) {
        type = "video";
      }
      return type;
    },
  }
}
</script>

<style lang="scss" scoped>
.detail-header {
  display: flex;
  justify-content: space-between;

  .detail-header-left {
    .chart-title {
      font-size: 18px;
      font-family: SimHei;
      font-weight: bold;
      color: #101010;
      box-sizing: border-box;

      &:before {
        content: '';
        display: inline-block;
        width: 13px;
        height: 32px;
        background-color: #FF944B;
        border-radius: 25%;
        vertical-align: -40%;
        margin-right: 20px;
      }
    }
  }

  .detail-header-right {
    i {
      &:first-child {
        margin-right: 20px;
      }
    }
  }
}

::v-deep .el-card__header {
  border-bottom: unset;
}

.creative-list {
  display: grid;
  grid: repeat(2,200px) /repeat(5,1fr);
  grid-gap: 10px;

  .creative-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .creative-item-content {
      margin-top: 13px;
      width: 100%;
      font-size: 12px;
      color: #101010;

      div {
        margin-bottom: 5px;
      }
    }
  }
}

.disabled {
  color: #EEEEEE;
  cursor: default !important;
}
</style>
